import { API_CONFIG } from '../config'
import { authApi } from './authApi'

// Token刷新定时器管理
export const tokenRefreshManager = {
  timer: null,
  
  start: () => {
    if (tokenRefreshManager.timer) {
      clearInterval(tokenRefreshManager.timer)
    }

    tokenRefreshManager.timer = setInterval(async () => {
      try {
        await authApi.refreshToken()
        console.log('Token refreshed successfully')
      } catch (error) {
        console.error('Failed to refresh token:', error)
      }
    }, API_CONFIG.tokenRefreshInterval)
  },
  
  stop: () => {
    if (tokenRefreshManager.timer) {
      clearInterval(tokenRefreshManager.timer)
      tokenRefreshManager.timer = null
    }
  }
} 